//
//  TabBarViewController.m
//  项目二
//
//  Created by rimi on 16/5/21.
//  Copyright © 2016年 objective. All rights reserved.
//

#import "TabBarViewController.h"
#import "ContactViewController.h"
#import "DynamicViewController.h"
#import "MessageViewController.h"
#import "InformationCenter.h"
@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self aa];
}
-(void)aa{
/**初始化标签控制器管理的视图控制器*/
    MessageViewController *mes = [MessageViewController new];
    ContactViewController *con = [ContactViewController new];
    DynamicViewController *dyn = [DynamicViewController new];
    /**将标签控制器管理的视图器存入数组中，在后面通过遍历进行统一配置*/
    NSArray *vcs = @[mes,con,dyn];
    /**准备视图控制器数据*/
    NSArray *vcTitles = @[@"消息",@"联系人",@"动态"];
    /**创建空的数组放置导航控制器*/
    NSMutableArray *newvcs = [@[]mutableCopy];
    /**tab图片*/
    NSArray *array = [NSArray arrayWithObjects:@"iconfont-lianxiren副本",@"iconfont-star副本",@"iconfont-xiaoxi副本", nil];
    NSArray *selectarray = [NSArray arrayWithObjects:@"iconfont-lianxiren-select副本",@"iconfont-star-select副本",@"iconfont-xiaoxi-select副本", nil];
    /**遍历视图控制器集合，统一配置*/
    [vcs enumerateObjectsUsingBlock:^(UIViewController * _Nonnull vc, NSUInteger idx, BOOL * _Nonnull stop) {
        /**标题*/
        vc.title = vcTitles[idx];
        vc.view.backgroundColor = [UIColor whiteColor];
        vc.tabBarItem = [[UITabBarItem alloc]initWithTitle:vcTitles[idx] image:[UIImage imageNamed:array[idx]] selectedImage:[UIImage imageNamed:selectarray[idx]]];
        /**配置 UINavigationItem*/
        vc.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"菜单" style:UIBarButtonItemStylePlain target:self action:@selector(respondNavigationItem:)];
        /**为视图控制器添加导航栏*/
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
        [newvcs addObject:nav];
    }];
    /**设置标签控制器管理的视图控制器*/
    self.viewControllers = newvcs;
    self.selectedIndex = 0;
    /**为标签控制器的视图设置阴影*/
    /**阴影颜色*/
    self.view.layer.shadowColor = [UIColor colorWithWhite:0.75 alpha:1.f].CGColor;
    /**往左偏移10个像素*/
    self.view.layer.shadowOffset = CSM(-10, 0);
    /**设置阴影不透明*/
    self.view.layer.shadowOpacity = 1.f;
}
#pragma mark - UIBarButtonItem
-(void)respondNavigationItem:(UIBarButtonItem *)sender{
    /**将方法名用字符串显示出来*/
    NSLog(@"%@",NSStringFromSelector(_cmd));
    
    /**更新菜单显示状态*/ /**单例传值*/
    GET_DEFAULT_INFORMATIONCENTER.ShowMenuView =!GET_DEFAULT_INFORMATIONCENTER.ShowMenuView;
    /**获取屏幕中心点的坐标*/
    [UIView animateWithDuration:.2f animations:^{
       /**位移*/
        self.view.center = CPM(GET_DEFAULT_INFORMATIONCENTER.ShowMenuView ? CENTER_X + 250 : CENTER_X, CENTER_Y);
        /**缩放*/
        if (GET_DEFAULT_INFORMATIONCENTER.ShowMenuView) {
            self.view.transform = CGAffineTransformMakeScale(0.8, 0.8);
        }
        else{
        /**还原*/
            self.view.transform = CGAffineTransformIdentity;
        }
    }];
}
@end
